package com.mediastory.spsserver.customer.dao.impl;

import java.util.List;
import java.util.Map;

import org.apache.ibatis.session.RowBounds;
import org.mybatis.spring.support.SqlSessionDaoSupport;
import org.springframework.stereotype.Repository;

import com.mediastory.spsserver.customer.dao.CustomerDao;
import com.mediastory.spsserver.customer.domain.Customer;

/**
 * @author Jaewon Choi
 */

@Repository
public class CustomerDaoImpl extends SqlSessionDaoSupport  implements CustomerDao {

	public CustomerDaoImpl() {
		// TODO Auto-generated constructor stub
	}

	@Override
	public List<Customer> SelectList(Map<String, Object> condition)
			throws Exception {
		// TODO Auto-generated method stub
		Integer page = (Integer)condition.get("page");
		Integer maxnum = (Integer)condition.get("maxnum");
		
		List<Customer> result = null;
		if(page != null && maxnum != null){
			RowBounds rb = new RowBounds(page, maxnum);
			result = getSqlSession().selectList("Customer.selectList", condition, rb);
		}else{
			result = getSqlSession().selectList("Customer.selectList", condition);
		}
		
		return result;
	}
	
	@Override
	public Integer SelectListTotalCnt(Map<String, Object> condition)
			throws Exception {
		// TODO Auto-generated method stub
		Integer result = getSqlSession().selectOne("Customer.selectListTotalCnt", condition);
		return result;
	}

	@Override
	public Customer select(Integer idx) throws Exception {
		// TODO Auto-generated method stub
		Customer result = (Customer)(getSqlSession().selectOne("Customer.select", idx)); 
		return result;
	}

	@Override
	public Customer insert(Customer customer) throws Exception {
		// TODO Auto-generated method stub
		int result = getSqlSession().insert("Customer.insert", customer);
		return customer;
	}

	@Override
	public Customer update(Customer customer) throws Exception {
		// TODO Auto-generated method stub
		int result = getSqlSession().update("Customer.update", customer);
		return customer;
	}

	@Override
	public int delete(Map<String, Object> condition) throws Exception {
		// TODO Auto-generated method stub
		int result = getSqlSession().update("Customer.delete", condition);
		return result;
	}

}
